package com.zlm.common.util;

import com.zlm.common.dto.userEmp.LoginAppParamsDto;
import com.zlm.common.constants.CodeConstants;
import com.zlm.common.dto.userEmp.EmpInfoParamsDto;
import com.zlm.common.dto.userEmp.EmpPunchParamsDto;
import com.zlm.common.dto.userEmp.EmpResumeParamsDto;
import com.zlm.common.entity.EmpUserEducationDO;
import com.zlm.common.entity.EmpUserExperienceDO;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

import java.math.BigDecimal;

/**
 * 校验参数工具类
 * @Author: duyufu
 * @Date: 2019/4/19 10:52
 */
public class CheckParamsUtils {

    public static boolean checkMobile(String mobile) {
        if (null == mobile || !RegexUtils.isMobileSimple(mobile)) {
            return false;
        }
        return true;
    }

    /**
     * 手机号密码检查
     * @param loginAppParamsDto
     * @return
     */
    public static Pair<Boolean, String> checkLoginPwdParams(LoginAppParamsDto loginAppParamsDto) {
        if (!checkMobile(loginAppParamsDto.getMobile())) {
            return Pair.of(false, CodeConstants.CODE_10001);
        }
        if (StringUtils.isBlank(loginAppParamsDto.getPassword())) {
            return Pair.of(false, CodeConstants.CODE_10003);
        }
        return Pair.of(true, "");
    }

    /**
     * 手机号验证码检查
     * @param loginAppParamsDto
     * @return
     */
    public static Pair<Boolean, String> checkLoginAwdParams(LoginAppParamsDto loginAppParamsDto) {
        if (!checkMobile(loginAppParamsDto.getMobile())) {
            return Pair.of(false, CodeConstants.CODE_10001);
        }
        if (StringUtils.isBlank(loginAppParamsDto.getActivationCode())) {
            return Pair.of(false, CodeConstants.CODE_10002);
        }
        return Pair.of(true, "");
    }

    /**
     * 检查修改密码参数
     *
     * @param loginAppParamsDto
     * @return
     */
    public static Pair<Boolean, String> checkUpdatePwdParams(LoginAppParamsDto loginAppParamsDto) {
        Pair<Boolean, String> pair = checkLoginPwdParams(loginAppParamsDto);
        if (!pair.getLeft()) {
            return pair;
        }
        if (StringUtils.isBlank(loginAppParamsDto.getActivationCode())) {
            return Pair.of(false, CodeConstants.CODE_10002);
        }
        return Pair.of(true, "");
    }

    /**
     * 检查用户基本信息参数
     * @param
     * @return
     */
    public static boolean checkEmpInfo(EmpInfoParamsDto empInfoParamsDto) {
        if (StringUtils.isBlank(empInfoParamsDto.getEmpName())) {
            return false;
        }
        if (null == empInfoParamsDto.getSex()) {
            return false;
        }
        if (StringUtils.isBlank(empInfoParamsDto.getBirthdayString())) {
            return false;
        }
        if (StringUtils.isBlank(empInfoParamsDto.getMobile())) {
            return false;
        }
        if (null == empInfoParamsDto.getIsWork()) {
            return false;
        }
        if (null == empInfoParamsDto.getEducation()) {
            return false;
        }
        empInfoParamsDto.setBirthday(DateTimeUtils.dateString2Date(empInfoParamsDto.getBirthdayString(),DateTimeUtils.FORMAT_DATE_DEFAULT));
        return true;
    }

    /**
     * 检查工作经历参数
     * @param empUserExperienceDO
     * @return
     */
    public static boolean checkExperience(EmpUserExperienceDO empUserExperienceDO) {
        if (StringUtils.isBlank(empUserExperienceDO.getStartDateString())) {
            return false;
        }
        if (StringUtils.isBlank(empUserExperienceDO.getEndDateString())) {
            return false;
        }
        if (StringUtils.isBlank(empUserExperienceDO.getCompanyName())) {
            return false;
        }
        if (StringUtils.isBlank(empUserExperienceDO.getPostName())) {
            return false;
        }
        if (StringUtils.isBlank(empUserExperienceDO.getDescription())) {
            return false;
        }
        empUserExperienceDO.setStartDate(DateTimeUtils.string1Date(empUserExperienceDO.getStartDateString()));
        empUserExperienceDO.setEndDate(DateTimeUtils.string1Date(empUserExperienceDO.getEndDateString()));
        return true;
    }

    /**
     * 检查教育经历
     * @param empUserEducationDO
     * @return
     */
    public static boolean checkEducation(EmpUserEducationDO empUserEducationDO) {
        if (StringUtils.isBlank(empUserEducationDO.getStartDateString())) {
            return false;
        }
        if (StringUtils.isBlank(empUserEducationDO.getEndDateString())) {
            return false;
        }
        if (StringUtils.isBlank(empUserEducationDO.getSchool())) {
            return false;
        }
        if (null == empUserEducationDO.getDegree()) {
            return false;
        }
        empUserEducationDO.setStartDate(DateTimeUtils.string1Date(empUserEducationDO.getStartDateString()));
        empUserEducationDO.setEndDate(DateTimeUtils.string1Date(empUserEducationDO.getEndDateString()));
        return true;
    }

    /**
     * 检查用户需求
     * @param empResumeParamsDto
     * @return
     */
    public static boolean checkResume(EmpResumeParamsDto empResumeParamsDto) {
        if (StringUtils.isBlank(empResumeParamsDto.getProvince()) || StringUtils.isBlank(empResumeParamsDto.getCity()) || StringUtils.isBlank(empResumeParamsDto.getArea())) {
            return false;
        }
        if (null == empResumeParamsDto.getPostId()) {
            return false;
        }
        if (null == empResumeParamsDto.getSalary()) {
            return false;
        }
//        if (null == empResumeParamsDto.getSysTimeSections()) {
//            return false;
//        }
        return true;
    }

    /**
     * 员工打卡参数检查
     * @param empPunchParamsDto
     * @return
     */
    public static boolean checkPunch(EmpPunchParamsDto empPunchParamsDto) {
        if (null == empPunchParamsDto.getOrgWorkTimeId()) {
            return false;
        }
        if (StringUtils.isBlank(empPunchParamsDto.getPunchDate())) {
            return false;
        }
        if (StringUtils.isBlank(empPunchParamsDto.getPunchAddress())) {
            return false;
        }
        if (StringUtils.isBlank(empPunchParamsDto.getLng())) {
            return false;
        }
        if (StringUtils.isBlank(empPunchParamsDto.getLat())) {
            return false;
        }
        empPunchParamsDto.setPunchLng(new BigDecimal(empPunchParamsDto.getLng()));
        empPunchParamsDto.setPunchLat(new BigDecimal(empPunchParamsDto.getLat()));
        return true;
    }

    public static boolean checkRealName(String realName, String idNo, String idImg1, String idImg2) {
        if (StringUtils.isBlank(realName)) {
            return false;
        }
        if (StringUtils.isBlank(idNo)) {
            return false;
        }
        if (StringUtils.isBlank(idImg1)) {
            return false;
        }
        if (StringUtils.isBlank(idImg2)) {
            return false;
        }
        return true;
    }
}
